/*
Date: October 2025
Project: Income and Child Maltreatment: Evidence from a Discontinuity in Tax Benefits
Author: Katherine Rittenhouse
Purpose: This code creates a log file in which p-values are displayed for use in 10b_qval.do (to calculate sharpened q values)
*/

clear all
set more off

set maxvar 32767


log using "p-values",replace
use "analysis.dta" if abs(et)<=60,clear
local bw 60
local lower -`bw'
local upper `bw'
local tick 10


local donutl 8
local donutr 8
local fmt tex

replace et = et*-1

*instrument = born in december
gen instrument = (et>0)
gen et_r = et*instrument
gen transformed = et/(`bw')
gen inbandwidth = abs(et)<`bw'
gen triwt = (1-abs(transformed))*inbandwidth
gen indonut = 0

replace indonut = 1 if et<-(`donutl'-1) | et>(`donutr')

keep if recentered<=2017

gen anysubstal0_2 = (numsu0_2>0 & numsu0_2!=.)


*Table 1 - RD estimates for all eight outcomes

foreach outcome in  "anyref0_2"  "anyinv0_2" "anysubstal0_2" "anypl0_2" "numref0_2" "numinv0_2" "numsu0_2" "dayspl0_2"  {
	
	reg `outcome' et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'
	
	reg `outcome' et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1 & lowinc==1, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'
	
	reg `outcome' et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1 & lowinc==0, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'

	
}


***through age 8 table

foreach outcome in numref numinv numsu dayspl {
gen `outcome'0_8 = `outcome'0_2+`outcome'3_5+`outcome'6_8 
}
foreach outcome in ref inv  {
gen any`outcome'0_8 = (num`outcome'0_8>0 & num`outcome'0_8!=.)

}

gen anypl0_8 = (dayspl0_8>0 & dayspl0_8!=.)
gen anysu0_8 = (numsu0_8>0 & numsu0_8!=.)

local count=1
foreach outcome in  "anyref" "anyinv" "anysu" "anypl" "numref" "numinv" "numsu" "dayspl"   {

	reg `outcome'0_2 et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1 & lowinc==1 & recentered<2012, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'

	reg `outcome'3_5 et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1 & lowinc==1 & recentered<2012, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'
	
	reg `outcome'6_8 et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1 & lowinc==1 & recentered<2012, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'
	
	reg `outcome'0_8 et et_r instrument i.recentered_yr [pw=triwt] if indonut==1 & childorder==1 & lowinc==1 & recentered<2012, vce(robust)
local t = _b[instrument]/_se[instrument]
local p = 2*ttail(e(df_r),abs(`t'))
di `p'
	
}
log close
	
